function [h0,hx,sigma] = unfoldTheta2(theta2,nx)

if nx == 2
    h0     = [theta2.h01    theta2.h02    ]';
    hx     = [theta2.hx11   theta2.hx12   ;
              theta2.hx21   theta2.hx22   ];
    sigma  = [theta2.sigma11  0               ;
              theta2.sigma21  theta2.sigma22  ];
elseif nx == 3
    h0     = [theta2.h01    theta2.h02    theta2.h03]';
    hx     = [theta2.hx11   theta2.hx12   theta2.hx13;
              theta2.hx21   theta2.hx22   theta2.hx23;
              theta2.hx31   theta2.hx32   theta2.hx33];
    sigma  = [theta2.sigma11  0               0 ;
              theta2.sigma21  theta2.sigma22  0 ;
              theta2.sigma31  theta2.sigma32  theta2.sigma33 ];
elseif nx == 4
    h0     = [theta2.h01    theta2.h02    theta2.h03   theta2.h04]';
    hx     = [theta2.hx11   theta2.hx12   theta2.hx13  theta2.hx14;
              theta2.hx21   theta2.hx22   theta2.hx23  theta2.hx24;
              theta2.hx31   theta2.hx32   theta2.hx33  theta2.hx34;
              theta2.hx41   theta2.hx42   theta2.hx43  theta2.hx44];
    sigma  = [theta2.sigma11  0               0                 0;
              theta2.sigma21  theta2.sigma22  0                 0;
              theta2.sigma31  theta2.sigma32  theta2.sigma33    0;
              theta2.sigma41  theta2.sigma42  theta2.sigma43    theta2.sigma44];
end

end

